package entertainmentguide.entity;

import java.util.StringTokenizer;
/**
 *
 * 
 */
public class PriceRange {
    private int priceRangeId;
    private double lowestPrice;
    private double highestPrice;

    public PriceRange(int priceRangeId, double lowestPrice, double highestPrice) {
        this.priceRangeId = priceRangeId;
        this.lowestPrice = lowestPrice;
        this.highestPrice = highestPrice;
    }

    public PriceRange() {
        this.priceRangeId=0; // δημιουργείται αυτόματα
    }

    public void setPriceRangeId(int priceRangeId) {
        this.priceRangeId = priceRangeId;
    }

    public int getPriceRangeId() {
        return priceRangeId;
    }

    public void setLowestPrice(double lowestPrice) {
        this.lowestPrice = lowestPrice;
    }

    public double getLowestPrice() {
        return lowestPrice;
    }

    public void setHighestPrice(double highestPrice) {
        this.highestPrice = highestPrice;
    }

    public double getHighestPrice() {
        return highestPrice;
    }

    public String toLabel(){
        return this.lowestPrice +" έως "+ this.highestPrice + " ευρώ";
    }
    
    @Override
    public String toString(){
        return  "\n" + " | " + "ID: " + getPriceRangeId() + " | " +
                "Από: " + getLowestPrice() + " | " +
                "έως: " + getHighestPrice() + " | ";
    }

    /**
     * Creates an PriceRange object by parsing line.
     * The line must be in the following format:
     * PRICERANGE: <restId> <lowestPrice> <highestPrice>
     *
     * @param line
     * @return
     */
    public static PriceRange parsePriceRange(String line) throws IllegalArgumentException{
        StringTokenizer strTok = new StringTokenizer(line);
        String s1 = strTok.nextToken(); // PriceRange:
        String s2 = strTok.nextToken(); // priceRangeId
        String s3 = strTok.nextToken(); // lowestPrice
        String s4 = strTok.nextToken(); // highestPrice
        strTok.nextToken("\""); //Skip the first toker with "

        int d2 = Integer.parseInt(s2);
        Double d3 = Double.parseDouble(s3);
        Double d4 = Double.parseDouble(s4);

        return new PriceRange(d2,d3,d4);
    }

}
